package com.project.web.order.controller.app.AppNative;

import com.github.pagehelper.PageInfo;
import com.project.common.core.utils.exception.Result;
import com.project.web.order.controller.common.BaseController;
import com.project.web.order.model.app.Product;
import com.project.web.order.service.app.ProductService;
import com.project.web.util.exception.ORDER_RESP_CODE_ENUM;
import com.project.web.util.exception.OrderCustomException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * App 商品API
 *
 * @Author: wyy
 * @Date: 2021-02-02 02:24
 */
@Api(tags = "【App】App商品API")
@RestController("appOrderProductController")
@RequestMapping("/order/auth/product/app")
public class ProductController extends BaseController {

    @Resource(name = "productServiceImpl")
    private ProductService productService;

    /**
     * 查询所有已上架商品
     *
     * @param
     * @return
     */
    @ApiOperation(value = "查询所有已上架商品")
    @GetMapping(value = "/getProductsOfNormal")
    public Result<List<Product>> getProductsOfNormal() {
        // 查询商品列表
        List<Product> productsOfNormal = productService.getProductsOfNormal();
        return getResult(productsOfNormal);
    }

    /**
     * 根据商品Id查询商品
     *
     * @param productId 商品Id
     * @return
     */
    @ApiOperation(value = "根据商品Id查询商品")
    @GetMapping(value = "/getById")
    public Result<Product> getById(Long productId) {
        // 初始化分页参数
        if (productId == null) {
            throw new OrderCustomException(ORDER_RESP_CODE_ENUM.MISS_PARAMETER);
        }
        Product product = productService.getById(productId);
        return getResult(product);
    }

}
